package cn.liontalk.common.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Protocol;

/**
 * @author: 周哲
 * @package: cn.liontalk.common.redis
 * @description:
 * @date: 2019/1/18 20:05
 * @version: V1.0
 */
@Service
public class RedisPoolFactory {

    @Autowired
    private RedisConfig redisConfig;


    @Bean
    public JedisPool getJedisPoolFactory() {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(redisConfig.getMaxIdle());
        jedisPoolConfig.setMinIdle(redisConfig.getMinIdle());
        jedisPoolConfig.setMaxWaitMillis(redisConfig.getMaxWait() * 1000);
        return new JedisPool(jedisPoolConfig, redisConfig.getHost(),
                redisConfig.getPort(),
                redisConfig.getTimeout() * 1000,
                redisConfig.getPassword(), Protocol.DEFAULT_DATABASE);

    }
}
